package com.example.software.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.software.utils.PageUtils;
import com.example.software.utils.Query;

import com.example.software.dao.DepartmentDao;
import com.example.software.entity.DepartmentEntity;
import com.example.software.service.DepartmentService;


@Service("departmentService")
public class DepartmentServiceImpl extends ServiceImpl<DepartmentDao, DepartmentEntity> implements DepartmentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        LambdaQueryWrapper<DepartmentEntity> wrapper = new LambdaQueryWrapper<>();

        if (params.containsKey("name")) {

            String name = (String) params.get("name");
            System.out.println("name:"+name);
            wrapper.like(StringUtils.isNotBlank(name), DepartmentEntity::getDepartmentName, name);
        }

        IPage<DepartmentEntity> page = this.page(
                new Query<DepartmentEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}